<template>
	<view>
		<view class="list" v-for="(item,index) in list">
			<view class="tit">{{item.type_text}}</view>
			<view>提现金额：<text style="color: #FF6543;font-weight: bold;">{{item.transfer_amount}}</text></view>
			<view>状态：<text style="color: green;font-weight: bold;">{{item.status}}</text></view>
			<view class="time" v-if="item.status=='WAIT_USER_CONFIRM'">提示：（24小时内可确认收款）</view>
			<view class="time">创建时间：{{item.create_time}}</view>
			<view class="btn" v-if="item.status=='WAIT_USER_CONFIRM'" @click="toConfirm(item.package_info)">确认收款</view>
		</view>
		<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
		<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
	</view>
</template>

<script>
	import {
		transferList,
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
			};
		},
		onLoad() {
			this.getlist()
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
				} = that;
				let obj = {
					size: offset,
					page: page + 1,
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await transferList(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							console.log((888))
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
			toConfirm(info) {
				if (uni.canIUse('requestMerchantTransfer')) {
					uni.requestMerchantTransfer({
						mchId: '1670427401',
						appId: 'wx3ed48d50aa14410a',
						package: info,
						success: (res) => {
							// res.err_msg将在页面展示成功后返回应用时返回ok，并不代表付款成功
							console.log('success:', res);

						},
						fail: (res) => {
							console.log('fail:', res);
							uni.showToast({
								title: res,
								icon: 'error'
							})

						},
					});
				} else {
					uni.showModal({
						content: '你的微信版本过低，请更新至最新版本。',
						showCancel: false,
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		background: white;
		padding: 20rpx;
		margin: 20rpx;
		font-size: 26rpx;

		view {
			margin-bottom: 10rpx;
		}

		.tit {
			font-size: 30rpx;
			font-weight: bold;
			margin-bottom: 15rpx;
		}

		.time {
			color: gray;
			font-size: 24rpx;
		}
	}

	.btn {
		margin-left: auto;
		width: fit-content;
		background: #FF6543;
		color: white;
		padding: 10rpx 20rpx;
		border-radius: 40rpx;
	}
</style>